<?php
/**
 * 仓库
 * Created by PhpStorm.
 * User: echa
 * Date: 2018/2/1
 * Time: 21:27
 */
namespace App\Services\Warehouse;


class WarehouseService extends PublicService {
    //仓库表单ID
    //protected $Formid = 'BD_STOCK';


    public function __construct()
    {
        parent::__construct(Config('k3cloud.Warehouse'));
    }

    /**
     *单据列表查询
     * 1.data：Json格式数据（详情参考Json格式数据）（必录）
    1.1.FormId：业务对象表单Id（必录）
    1.2.FieldKeys：字段keys，字符串类型用逗号分隔，比如"key1,key2..."（必录）
    1.3.FilterString：过滤（非必录）  FNumber=''
    1.4.OrderString：排序字段（非必录）
    1.5.TopRowCount：总行数（非必录）
    1.6.StartRow：开始行（非必录）
    1.7.Limit：最大行数，不能超过2000（非必录）
     */
    public function ExecuteBillQueryWarehouse($FieldKeys='',$FilterString='',$OrderString='',$TopRowCount=0,$StartRow=0,$Limit=20)
    {
            if (empty($FieldKeys)) {
                $FieldKeys = 'FStockId,FNumber,FName,FAddress,FPrincipal,FStockProperty,FDocumentStatus';
            }
        return $this->ExecuteBillQuery($FieldKeys,$FilterString,$OrderString,$OrderString,$StartRow,$Limit);
    }

    /**
    *  根据具体的仓库ID或者仓库编号获取数据，若不传，默认读取
     * 参数说明
     * $FStockId   仓库ID
     * $FNumber  仓库编号
     * 字段说明
     * FStockId   仓库ID
     * FNumber   仓库编号
     * FName  仓库名称
     */
    public function ListWarehouse($FStockId='',$FNumber=''){
        $FieldKeys='FStockId,FNumber,FName,FDocumentStatus';
        $FilterString="FDocumentStatus='c'"; //已审核
        if(!empty($FStockId)){
            $FilterString.=" and FStockId=".$FStockId;
        }
        if(!empty($FNumber)){
            $FilterString.=" and FNumber='".$FNumber."'";
        }
        $list=$this->ExecuteBillQuery($FieldKeys,$FilterString,Null,Null,0,2000);
        if($list){
            return $list;
        }else{
            return false;
        }
    }

    /***
     * 根据仓库编号查询对应的仓库明细
     * @param $FNumber
    @author echa
     * @return array|bool|mixed
     */
    public function GetWarehouseInfo($FNumber){
        $FieldKeys='FStockId,FNumber,FName,FGroup,FGroup.FName,F_PAEZ_type,FDocumentStatus';
        $FilterString="FNumber='".$FNumber."'";
        $list=$this->ExecuteBillQuery($FieldKeys,$FilterString);
        if($list){
            return $list;
        }else{
            return false;
        }
    }

    /***
     * 根据仓库编号筛选相同分组下面指定仓库类型数据
     * @param $FNumber  主仓库编号
     * @param $Type  A-主  B-次  C-退  D-待处理
    @author echa
     * @return array|bool|mixed
     */
    public function GetWarehouseTypeInfo($FNumber,$Type){
        $return=$this->GetWarehouseInfo($FNumber);
        if($return){
            $FieldKeys='FStockId,FNumber,FName,FGroup,FGroup.FName,F_PAEZ_type,FDocumentStatus';
            $FilterString="F_PAEZ_type='".$Type."' and FGroup=".$return[0]['FGroup'];
            $list=$this->ExecuteBillQuery($FieldKeys,$FilterString);
            if($list){
                return $list;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }
}